import { MICRO_SERVICE_ADMIN } from '~/constants/service-constant.ts'
import type { MenuReq, MenuResp } from '~/api/setting/model/menu.ts'

enum Api {
  QueryMenuTreeList = '/webservice/menu/queryMenuTreeList',
  QueryMenuCheckedTreeListOfPermissionId = '/webservice/menu/queryMenuCheckedTreeListOfPermissionId',
  QueryCheckedMenuTreeListByPermissionId = '/webservice/menu/queryCheckedMenuTreeListByPermissionId',
  CreateMenu = '/webservice/menu/createMenu',
  ModifyMenu = '/webservice/menu/modifyMenu',
  EnabledMenuStateById = '/webservice/menu/enabledMenuStateById',
  RemoveMenuById = '/webservice/menu/removeMenuById',
}

/**
 * 获取菜单树
 */
export function queryMenuTreeListApi() {
  return usePost<MenuResp[], MenuReq>(MICRO_SERVICE_ADMIN + Api.QueryMenuTreeList)
}

/**
 * 标记权限选中的菜单树
 * @param params 菜单实体
 */
export function queryMenuCheckedTreeListOfPermissionIdApi(params?: MenuReq) {
  return usePost<MenuResp[], MenuReq>(MICRO_SERVICE_ADMIN + Api.QueryMenuCheckedTreeListOfPermissionId, params)
}

/**
 * 根据权限ID，查询菜单树列表
 * @param params 菜单实体
 */
export function queryCheckedMenuTreeListByPermissionId(params?: MenuReq) {
  return usePost<MenuResp[], MenuReq>(MICRO_SERVICE_ADMIN + Api.QueryCheckedMenuTreeListByPermissionId, params)
}

/**
 * 创建菜单
 * @param params 菜单实体
 */
export function createMenuApi(params?: MenuReq) {
  return usePost<boolean, MenuReq>(MICRO_SERVICE_ADMIN + Api.CreateMenu, params)
}

/**
 * 修改菜单
 * @param params 菜单实体
 */
export function modifyMenuApi(params?: MenuReq) {
  return usePost<boolean, MenuReq>(MICRO_SERVICE_ADMIN + Api.ModifyMenu, params)
}

/**
 * 开启或关闭菜单状态
 * @param params 菜单实体
 */
export function enabledMenuStateByIdApi(params?: MenuReq) {
  return useGet<boolean, MenuReq>(MICRO_SERVICE_ADMIN + Api.EnabledMenuStateById, params)
}

/**
 * 删除菜单
 * @param params 菜单实体，使用其中ID
 */
export function removeMenuByIdApi(params?: MenuReq) {
  return useGet<boolean>(MICRO_SERVICE_ADMIN + Api.RemoveMenuById, params)
}
